package com.mrd.shiptask_shipowner.constants.database;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import android.annotation.SuppressLint;

/**
 * <p>
 * application name: sample
 * <p>
 * copyright: Copyright@2012 ���Ƽ����޹�˾
 */
/**
 * @author qiul
 */
public class DateUtil {
	/**
	 * Ĭ�ϸ�ʽ����ʽ
	 */
	public static final String	DEFAULT_FORMAT_TYPE	       = "yyyy-MM-dd";

	public static final String	FORMAT_DATETIME_TYPE	   = "yyyy-MM-dd HH:mm:ss";

	public static final String	YEAR_MONTH_DAY_HOUR_MINUTE	= "yyyy-MM-dd HH:mm";

	/**
	 * ��yyyy-MM-dd��ʽ��ʽ��ʱ��
	 * @param date
	 * @return
	 */
	public static String formatDate(Date date) {
		return formatDate(date, DEFAULT_FORMAT_TYPE);
	}

	/**
	 * ��ָ����ʽ��ʽ��ʱ��
	 * @param date
	 *            ��Ҫ��ʽ����ʱ��
	 * @param formatType
	 *            ��ʽ
	 * @return ��ʽ�����ֵ
	 */
	@SuppressLint("SimpleDateFormat")
	public static String formatDate(Date date,String formatType) {
		if(formatType == null || "".equals(formatType)) {
			formatType = DEFAULT_FORMAT_TYPE;
		}
		SimpleDateFormat sdf = new SimpleDateFormat(formatType);
		return sdf.format(date);
	}

	/**
	 * ��ָ����ʽ��ʽ��ʱ��
	 * @param dateStr
	 *            ��Ҫ��ʽ����ʱ��
	 * @param formatType
	 *            ��ʽ
	 * @return ��ʽ�����ֵ
	 * @throws ParseException
	 */
	@SuppressLint("SimpleDateFormat")
	public static Date parseString(String dateStr,String formatType) throws ParseException {
		if(formatType == null || "".equals(formatType)) {
			formatType = DEFAULT_FORMAT_TYPE;
		}
		SimpleDateFormat sdf = new SimpleDateFormat(formatType);
		return sdf.parse(dateStr);
	}
}
